﻿<%@ WebHandler Language="C#" Class="webservice" %>

using System;
using System.Web;
using System.Data;
using System.IO;
using System.Xml;

public class webservice : IHttpHandler {

    HttpRequest Request = null;
    HttpResponse Response = null;
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/xml";
        Request = context.Request;
        Response = context.Response;

        string action = Request.Form["action"];

        switch (action)
        {
            case "getuserlist": getUserList(); break;     //获取管理员列表
        }
    }

    /// <summary>
    /// 获取管理员列表
    /// </summary>
    private void getUserList()
    {
        BLL.Admin bll = new BLL.Admin();
        Response.Write(ConvertDataTableToXML(bll.GetList(0, "", "AddTime").Tables[0]));
    }
    
    /// <summary>
    /// DataTable转XML字符串
    /// </summary>
    /// <param name="dt"></param>
    /// <returns></returns>
    private string ConvertDataTableToXML(DataTable dt)
    {
        MemoryStream stream = null;
        XmlTextWriter writer = null;
        try
        {
            stream = new MemoryStream();
            writer = new XmlTextWriter(stream, System.Text.Encoding.Default);
            dt.WriteXml(writer);
            int count = (int)stream.Length;
            byte[] arr = new byte[count];
            stream.Seek(0, SeekOrigin.Begin);
            stream.Read(arr, 0, count);
            System.Text.UTF8Encoding utf = new System.Text.UTF8Encoding();

            return utf.GetString(arr).Trim();
        }
        catch
        {
            return "";
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}